using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Master.Dao;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Master.Bean;
using Shpm.System;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Utils;
public partial class App_Input_EvaluationTeacherUpdForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.ViewState["CURRICULUM_ID"] = this.Context.Items["CURRICULUM_ID"];
            this.ViewState["TEACHER_NAME"] = this.Context.Items["TEACHER_NAME"];
            this.ViewState["CLASS_NAME"] = this.Context.Items["CLASS_NAME"];
            this.Label1.Text = Convert.ToString(this.ViewState["TEACHER_NAME"]);
            this.Label2.Text = Convert.ToString(this.ViewState["CLASS_NAME"]);
            //this.ViewState["CURRICULUM_ID"] = 2;

            if (Context.Items.Contains("NAME"))
            {
                this.ViewState["NAME"] = Context.Items["NAME"];
            }
            if (Context.Items.Contains("TYPE"))
            {
                this.ViewState["TYPE"] = Context.Items["TYPE"];
            }
            if (Context.Items.Contains("DO"))
            {
                this.ViewState["DO"] = Context.Items["DO"];
            }
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            EvaluationUpdBean dataBean = (EvaluationUpdBean)e.Row.DataItem;
            RadioButtonList taiduLst = e.Row.Cells[2].Controls[1] as RadioButtonList;
            RadioButtonList chengjiLst = e.Row.Cells[3].Controls[1] as RadioButtonList;
            if (dataBean.StudentTaidu != null)
            {
                taiduLst.SelectedValue = dataBean.StudentTaidu;
            }
            if (dataBean.StudentChenji != null)
            {
                chengjiLst.SelectedValue = dataBean.StudentChenji;
            }
        }
    }

    protected override void OnPreRender(EventArgs e)
    {
        EvaluationUpdBean dataBean = new EvaluationUpdBean();
        EvaluationSrhDao Dao = new EvaluationSrhDao();

        dataBean.CurriculumId = Convert.ToInt32(this.ViewState["CURRICULUM_ID"]);
        IList list = Dao.ListStudent(dataBean);

        GridView1.DataSource = list;
        GridView1.DataBind();
        if (list.Count == 0)
        {
            tbl2.Visible = false;
        }
        else
        {
            tbl2.Visible = true;
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        EvaluationSrhDao Dao = new EvaluationSrhDao();
        if (tbl2.Visible)
        {
            IList lst = new ArrayList();
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                EvaluationUpdBean dataBean = new EvaluationUpdBean();
                dataBean.StudentId = Convert.ToInt32(GridView1.Rows[i].Cells[0].Text);
                RadioButtonList taiduLst = GridView1.Rows[i].Cells[2].Controls[1] as RadioButtonList;
                RadioButtonList chengjiLst = GridView1.Rows[i].Cells[3].Controls[1] as RadioButtonList;
                dataBean.StudentTaidu = taiduLst.SelectedValue;
                dataBean.StudentChenji = chengjiLst.SelectedValue;
                lst.Add(dataBean);
            }
            Dao.Upd(lst);
            ((Design_MasterPage)this.Master).InfoMessage =
                          HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0002").ToString();
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Context.Items["NAME"] = this.ViewState["NAME"];
        Context.Items["TYPE"] = this.ViewState["TYPE"];
        Context.Items["DO"] = this.ViewState["DO"];
        string url = "~/App/Input/EvaluationSrhForm.aspx";
        ControllerUtils.Transfer(Context, url, true);  
    }
}
